﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenSoftStore.Client.Common;
using OpenSoftStore.Orm.Model;

namespace OpenSoftStore.Client.UIL.ManageMember.Info
{
    public partial class MemberInfoEdit : UserControl
    {
        public T_Member Member;
        public Boolean Drog = false;
        public int Top = 0;
        public int Left = 0;

        public MemberInfoEdit()
        {
            InitializeComponent();
            SPACommon.SetUiStyle(this);
            trTree.ExpandAll();
            Member=new T_Member();
        }

        public void SetMember(T_Member member)
        {
            Member = member;
        }

        private void trTree_AfterSelect(object sender, TreeViewEventArgs e)
        {
            var node = trTree.SelectedNode;
            pblLeft.Controls.Clear();
            switch (node.Name)
            {
                case "Member":
                    pblLeft.Controls.Add(BaseInfo.Instance);
                    BaseInfo.Instance.Dock = DockStyle.Fill;
                    BaseInfo.Instance.GetMember(Member);
                    break;
                case "BaseInfo":
                    pblLeft.Controls.Add(BaseInfo.Instance);
                    BaseInfo.Instance.Dock = DockStyle.Fill;
                    break;
                case "Dinner":
                    pblLeft.Controls.Add(Dinner.Instance);
                    Dinner.Instance.Dock = DockStyle.Fill;
                    Dinner.Instance.GetDinner(Member);
                    break;
                case "InValue":
                    pblLeft.Controls.Add(InValue.Instance);
                    InValue.Instance.Dock = DockStyle.Fill;
                    InValue.Instance.GetMemberValueRecords(Member);
                    break;
                case "Owed":
                    pblLeft.Controls.Add(Owed.Instance);
                    Owed.Instance.Dock = DockStyle.Fill;
                    Owed.Instance.GetOweds(Member);
                    break;
                case "Bill":
                    pblLeft.Controls.Add(Bill.Instance);
                    Bill.Instance.Dock = DockStyle.Fill;
                    Bill.Instance.GetBills(Member);
                    break;
                case "Remind":
                    pblLeft.Controls.Add(Remind.Instance);
                    Remind.Instance.Dock = DockStyle.Fill;
                    Remind.Instance.GetReminds(Member);
                    break;
            }
        }

        private void pbClose_Click(object sender, EventArgs e)
        {
            var findForm = FindForm();
            if (findForm == null) return;
            findForm.DialogResult = DialogResult.Cancel;
            findForm.Close();
        }

        private void PnlInfoTitle_MouseDown(object sender, MouseEventArgs e)
        {
            Drog = true;
            Top = e.Y;
            Left = e.X;
        }

        private void PnlInfoTitle_MouseMove(object sender, MouseEventArgs e)
        {
            if (!Drog) return;
            var findForm = FindForm();
            if (findForm == null) return;
            findForm.Top += e.Y - Top;
            findForm.Left += e.X - Left;
        }

        private void PnlInfoTitle_MouseUp(object sender, MouseEventArgs e)
        {
            Drog = false;
        }
    }
}
